package com.liangzhong.controller
{	
	import com.liangzhong.constants.NotificationConstants;
	import com.liangzhong.manager.DomainManager;
	import com.liangzhong.message.tcp.GameSocket;
	import com.liangzhong.model.AppData;
	import com.liangzhong.proxy.bag.BagProxy;
	import com.liangzhong.proxy.chat.ChatProxy;
	import com.liangzhong.proxy.lobby.LobbyProxy;
	import com.liangzhong.proxy.logic.LogicProxy;
	import com.liangzhong.proxy.login.LoginProxy;
	import com.liangzhong.proxy.mail.MailProxy;
	import com.liangzhong.proxy.shop.ShopProxy;
	import com.liangzhong.view.tips.BaseTips;
	import com.liangzhong.view.tips.CommonTips;
	import com.socket.clientsocket.ClientSocket;
	import com.socket.clientsocket.SocketState;
	
	import lz.controls.managers.TipsManager;
	
	import org.puremvc.as3.interfaces.ICommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;


	/**
	 * 模型初始化
	 * @author lxh
	 * 
	 */	
	public class ModelPrepCommand extends SimpleCommand implements ICommand
	{
		public function ModelPrepCommand()
		{
			super();
		}
		/**
		 *执行处理  
		 * @param notification
		 * 
		 */		
		override public function execute(notification:INotification):void
		{
			var clientSocket :ClientSocket = GameSocket.getInstance().clientSocket;
			GameSocket.getInstance().facade = facade;
			//
			if(clientSocket.connectState == SocketState.SocketState_Connected)
			{
				sendNotification(NotificationConstants.Login_Connect_Server_Success);
				return;
			}
			//初始化
			DomainManager.initilaize();
			var loginProxy :LoginProxy = new LoginProxy();
			//添加login 回调接口
			clientSocket.addClientSocketHandler(loginProxy);
			loginProxy.clientSocket = clientSocket;
			facade.registerProxy(loginProxy);
			//logic
			var logicProxy :LogicProxy = new LogicProxy();
			clientSocket.addClientSocketHandler(logicProxy);
			logicProxy.clientSocket = clientSocket;
			facade.registerProxy(logicProxy);
			//lobby
			var lobbyProxy :LobbyProxy = new LobbyProxy();
			clientSocket.addClientSocketHandler(lobbyProxy);
			lobbyProxy.clientSocket = clientSocket;
			facade.registerProxy(lobbyProxy);
			//背包
			var bagProxy :BagProxy = new BagProxy();
			clientSocket.addClientSocketHandler(bagProxy);
			bagProxy.clientSocket = clientSocket;
			facade.registerProxy(bagProxy);
			//邮件
			var mailProxy :MailProxy = new MailProxy();
			clientSocket.addClientSocketHandler(mailProxy);
			mailProxy.clientSocket = clientSocket;
			facade.registerProxy(mailProxy);
			/*******聊天 ***********/
			var chatproxy:ChatProxy = new ChatProxy();
			clientSocket.addClientSocketHandler(chatproxy);
			chatproxy.clientSocket = clientSocket;
			facade.registerProxy(chatproxy);
			
			
			/*******商城******/
			var shopproxy:ShopProxy = new ShopProxy();
			clientSocket.addClientSocketHandler(shopproxy);
			shopproxy.clientSocket = clientSocket;
			facade.registerProxy(shopproxy);
			//connect
			clientSocket.connect(AppData.getInstance().ip,AppData.getInstance().port);
			//TipsManager register
			TipsManager.register(CommonTips);
			TipsManager.register(BaseTips);
		}
		
	}
}